package structures.tree;

import java.util.List;

// 实现 顺序存储二叉树  应用实例是堆排序 后续会涉及到
public class ArrayBinaryTreeDemo {
    public static void main(String[] args) {
        int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
        ArrayBinaryTree arrayBinaryTree = new ArrayBinaryTree(array);
        arrayBinaryTree.preOrder();

    }
}


class ArrayBinaryTree {
    private final int[] array;

    public ArrayBinaryTree(int[] array) {
        this.array = array;
    }

    public void preOrder() {
        preOrder(0);
    }

    public void preOrder(int index) {
        if (array == null || array.length == 0 || index >= array.length) {
            return;
        }

        System.out.println(array[index]);
        preOrder(index * 2 + 1);
        preOrder(index * 2 + 2);

    }
}